import axios from "axios"
const instance = axios.create({
    // baseURL: 'http://192.168.113.249:8081/cms'
    baseURL: "/api",
});
// 添加请求拦截器
instance.interceptors.request.use(
    function(config) {
        console.log("这里是请求拦截器1....");
        let token = localStorage.getItem("x-auth-token");
        if (token) {
            config.headers["x-auth-token"] = token
        }
        // config.headers.token = "aaa123456";
        return config;
    },
    function(error) {
        // 对请求错误做些什么
        return Promise.reject(error);
    }
);
// 添加响应拦截器
instance.interceptors.response.use(
    function(response) {
        console.log("这里是响应拦截器2....", response);
        if (response.data.code != 0 &&
            response.data.code != 400 &&
            response.data.code != 407) {
            alert("统一提示:" + response.data.message)
            return;
        }
        return response.data;
    },
    function(error) {
        // 对响应错误做点什么
        return Promise.reject(error);
    }
);

export default instance;